import React, { Component } from 'react';
import './style.css'
// import { Redirect } from 'react-router-dom';
import ReactEcharts from 'echarts-for-react';
import 'echarts-wordcloud'
import request from '../../request';
// import ReactEcharts from 'echarts-for-react';


class KeyWord extends Component{

  componentDidMount() {
    request.get('/api/isLogin').then(res => {
      const data: boolean = res.data;
      if (!data) {
        this.setState({
          isLogin: false,
          loading: false
        });
      } else {
        this.setState({
          loading: false
        });
      }
    });

    request.get('/api/showWenCaiData').then(res => {
      const data = res.data;
      if (data) {
        this.setState({ data });
      }
    });
  }


  option = {
    title: {
        text: '词云',//标题
        x: 'center',
        textStyle: {
            fontSize: 23
        }
 
    },
    backgroundColor: '#F7F7F7',
    tooltip: {
        show: true
    },
    series: [{
        name: '热点分析',//数据提示窗标题
        type: 'wordCloud',
        sizeRange: [6, 66],//画布范围，如果设置太大会出现少词（溢出屏幕）
        rotationRange: [-45, 90],//数据翻转范围
        //shape: 'circle',
        textPadding: 0,
        autoSize: {
            enable: true,
            minSize: 6
        },
        textStyle: {
            normal: {
                color: function() {
                    return 'rgb(' + [
                        Math.round(Math.random() * 160),
                        Math.round(Math.random() * 160),
                        Math.round(Math.random() * 160)
                    ].join(',') + ')';
                }
            },
            emphasis: {
                shadowBlur: 10,
                shadowColor: '#333'
            }
        },
        data: [{
            name: "数据一",
            value: 1000
        }, {
            name: "数据二",
            value: 520
        }]//name和value建议用小写，大写有时会出现兼容问题
    }]
  }

  render() {
    return (
      <div>
        <ReactEcharts option={this.option} />
      </div>
    )
  }
}

export default KeyWord
